﻿using System;
using System.Collections.Generic;

namespace HCore
{
    public class DisplayObjectFactory
    {
        public delegate DisplayObject DisplayCreator(BaseGameEntity entity);

        private static Dictionary<int, DisplayCreator> _creators = new Dictionary<int, DisplayCreator>();

        public static void SetDisplayCreator(int eType, Type type)
        {
            _creators[eType] = entity => { return (DisplayObject) Activator.CreateInstance(type, entity); };
        }

        public static DisplayObject CreateDisplayObject(BaseGameEntity entity)
        {
            int eType = entity.eType;
            if (!_creators.ContainsKey(eType))
            {
                return new NoneDisplay(entity);
            }

            return _creators[eType].Invoke(entity);
        }
    }
}